﻿
Public Class commonNaming
    Public Const id As String = "id"
    Public Const userRandomKey As String = "urk"
    Public Const userSiteRandomKey As String = "usrk"
    Public Const password As String = "pwd"
    Public Const host As String = "hst"
    Public Const returnUrl As String = "rtnurl"
End Class

Public Class query
    Public Const id As String = commonNaming.id
    Public Const userRandomKey As String = commonNaming.userRandomKey
    Public Const userSiteRandomKey As String = commonNaming.userSiteRandomKey
    Public Const host As String = commonNaming.host
    Public Const password As String = commonNaming.password
    Public Const returnUrl As String = commonNaming.returnUrl
    Public Const forceUpdate As String = "forceUpdate"
End Class

Public Class cookie
    Public Const id As String = commonNaming.id
    Public Const userRandomKey As String = commonNaming.userRandomKey
    Public Const userSiteRandomKey As String = commonNaming.userSiteRandomKey
End Class

Public Class uskResponse
    Public Class statusCode
        Public Const success As Int32 = Net.HttpStatusCode.OK
        Public Const notfound As Int32 = Net.HttpStatusCode.NotFound
        Public Const noIdInput As Int32 = Net.HttpStatusCode.BadRequest
        Public Const noHostInput As Int32 = Net.HttpStatusCode.BadRequest
        Public Const noValidIp As Int32 = Net.HttpStatusCode.PreconditionFailed
    End Class

    Public Class description
        Public Const success As String = "OK"
        Public Const notfound As String = "NOT FOUND"
        Public Const noIdInput As String = "NO ID INPUT"
        Public Const noHostInput As String = "NO HOST INPUT"
        Public Const noValidIp As String = "NO VALID IP"
    End Class
End Class

Public Class apiloginResponse
    Public Class statusCode
        Public Const success As Int32 = Net.HttpStatusCode.OK
        Public Const passwordError As Int32 = Net.HttpStatusCode.Unauthorized
        Public Const inputIncomplete As Int32 = Net.HttpStatusCode.BadRequest
        Public Const idNotFound As Int32 = Net.HttpStatusCode.PreconditionFailed
    End Class

    Public Class description
        Public Const success As String = "OK"
        Public Const passwordError As String = "PASSWORD ERROR"
        Public Const inputIncomplete As String = "INPUT INCOMPLETE"
        Public Const idNotFound As String = "ID NOT FOUND"
    End Class

    Public Class contentNaming
        Public Const id As String = commonNaming.id
        Public Const host As String = commonNaming.host
        Public Const userRandomKey As String = commonNaming.userRandomKey
        Public Const userSiteRandomKey As String = commonNaming.userSiteRandomKey
        Public Const returnUrl As String = commonNaming.returnUrl
    End Class

    Public Shared ReadOnly contentSeperator As String = newline.incode()
    Public Const contentNameValueSeperator As String = character.colon
End Class

Public Class storoomkey
    Private Class storoomPrefix
        Public Const idsystem As String = "idsystem"
        Public Const userRandomKey As String = commonNaming.userRandomKey
        Public Const password As String = commonNaming.password
        Public Const userSiteRandomKey As String = commonNaming.userSiteRandomKey
    End Class

    Private Shared Function generate(ByVal prefix As String, ByVal key As String) As String
        Return storoomPrefix.idsystem + character.dot + prefix + character.dot + key
    End Function

    Public Shared Function userRandom(ByVal id As String) As String
        assert(Not isemptystring(id))
        Return generate(storoomPrefix.userRandomKey, id)
    End Function

    Public Shared Function userPassword(ByVal id As String) As String
        assert(Not isemptystring(id))
        Return generate(storoomPrefix.password, id)
    End Function

    Public Shared Function userSiteRandom(ByVal id As String, ByVal host As String, ByVal ip As String) As String
        assert(Not isemptystring(id))
        assert(Not isemptystring(host))
        assert(Not isemptystring(ip))
        Return generate(storoomPrefix.userSiteRandomKey, id + character.dot + host + character.colon + ip)
    End Function
End Class

Public Module _idcommon
    Public Const minIdLength As Int64 = 5
    Public Const usrkPathIdentity As String = network.pathSeperator + commonNaming.userSiteRandomKey
    Public Const loginPathIdentity As String = network.pathSeperator + "login"
    Public Const apiloginPathIdentity As String = network.pathSeperator + "apilogin"
#If DEBUG Then
    Public Const defaultServerUrl As String = "http://id.hzj-jie.net:800/"
#Else
    Public Const defaultServerUrl As String = "http://id.hzj-jie.net/"
#End If
End Module